package server.mapper;

import server.HttpServlet;
import server.Servlet;
import server.WebappClassLoader;

/**
 * @author xingyi
 */
public class Wrapper {
    private String urlPattern;
    private String servletName;
    private String servletClass;
    private WebappClassLoader webappClassLoader;

    public String getUrlPattern() {
        return urlPattern;
    }

    public void setUrlPattern(String urlPattern) {
        this.urlPattern = urlPattern;
    }

    public String getServletName() {
        return servletName;
    }

    public void setServletName(String servletName) {
        this.servletName = servletName;
    }

    public String getServletClass() {
        return servletClass;
    }

    public void setServletClass(String servletClass) {
        this.servletClass = servletClass;
    }


    public void setClassLoader(WebappClassLoader webappClassLoader) {
        this.webappClassLoader = webappClassLoader;
    }

    public HttpServlet newServletInstance() throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        final Class<?> aClass = webappClassLoader.loadClass(servletClass);
        System.out.println(aClass);
        return (HttpServlet) aClass.newInstance();
    }
}
